<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    .add-tag{margin: 5px 0}
    .mainBox{bottom: 0!important;}

    #commentForm .main-container{padding-bottom: 50px!important;}
    .main-container{padding-top: 10px!important;}
    .add-tag{margin: 5px 0}
    .xuanmsg{color: #aaa;margin: 9px 0 5px 11px;font-size: 12px}
    .page-title{border-bottom: 10px solid #ecf0f1;}
    .bottss{width: 100%;height: 30px;position: fixed;bottom: 0;}

</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con"><span>同意</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">
        <div class="block-generic">

            <div id="coursetype_next" class="layui-hide">
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>选择下一步</label>
                            <div class="layui-input-block">
                                <div class="radio-block">
                                    <input type="radio" name="isnext" value="1" lay-filter="isnext" title="进入下一步审核" checked>
                                    <input type="radio" name="isnext" value="2" lay-filter="isnext" title="同意并结束">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" id="nexterDiv">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                            <div class="layui-input-block relative">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                    <div class="tanxiannei" id="nexter"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12 tes_box">
                        <label class="layui-form-label tes_label">处理意见</label>
                        <div class="layui-input-block tes_block" style="margin-left: 0 !important;">
                            <input type="hidden" name="agree" value="1">
                            <input type="text" name="explain" id="explain" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                            <div style="color: #1ca5ff;cursor: pointer;display: inline-block" class="add-tag" onclick="addFlowUsed()">加入常用说明</div>
                            <div class="tag-box" id="flow_used_div"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-hide" id="qianshen">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" style="height: 98px;line-height: 84px"><text>*</text>手写签名</label>
                        <div class="layui-input-block signshen">
                            <div class="deaqian deadea" onclick="openPage('flow_signshen.php')">
                                <span class="iico"><i class="layui-icon layui-icon-edit"></i></span>
                                <span class="qiantxt">点此签名</span>
                            </div>
                            <div class="deaqian deazhen layui-hide">
                                <img src="">
                                <i class="layui-icon layui-icon-close iiclose" onclick="delQian()"></i>
                                <input type="hidden" id="qian_id" name="qian_id">
                                <input type="hidden" id="qian" name="qian">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfotwo.php'?>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">抄送</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=promer&type=user&single=2');"></div>
                                <div class="tanxiannei" id="promer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=promer&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<div class="bottss"></div>
<script>
    var param_id = getQueryVariable('id') || 0;
    var param_isqian = getQueryVariable('isqian') || 0;
    if(param_isqian == 1){
        $("#qianshen").removeClass('layui-hide');
    }
    function delQian (){
        $(".signshen .deadea" ).removeClass('layui-hide');
        $(".signshen .deazhen").addClass('layui-hide');
        $(".signshen .deazhen img").attr('src', '');
        $("#qian_id").val('');
        $("#qian").val('');
    }


    var param_isnext = getQueryVariable('isnext') || 0;
    if(param_isnext > 0){
        $("#coursetype_next").removeClass('layui-hide');
    }


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;

        public_min_file_load('minfiles');

        facade.ajax({url: ask_opt_get_flow_used}).done(function(res){
            if (res.code === 2000) {
                show_flow_used(res.data);

                public_upload_file_load('upload_files');
                render_from();
            }
        });

        form.on('radio(isnext)', function(data){
            if(data.value == 1){
                $("#nexterDiv").removeClass('layui-hide');
            }else{
                $("#nexterDiv").addClass('layui-hide');
            }

            set_upd_yiju(data.value)
            reset_datas(1);
        });


        form.on('submit(add)', function(data){
            data.field.id = param_id;
            data.field.ispc = 1;
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            data.field.promer = tan_tags_getvalue("#promer", 'user');
            data.field.files = public_upload_file_value_str('upload_files');

            facade.ajax({url: ask_flow_examine_bill, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    facade.success('操作成功');
                    setTimeout(function () {
                        parent.window.location.reload();
                    },1500);
                }
            });

            return false;
        });
    });








    function show_flow_used(data) {
        var str = '';
        for (var key in data){
            str += '<div class="tag-box-div">';
            str += '<span class="tag-name" onclick="pushFlowUsed(this)">'+data[key].explain+'</span>';
            str += '<span class="tag-close" onclick="delFlowUsed('+data[key].id+')">×</span>';
            str += '</div>';
        }
        $("#flow_used_div").html(str);
    }

    function addFlowUsed() {
        var explain = $('#explain').val() || '';
        if(!explain){
            facade.error('请填写处理意见');return false;
        }
        layui.use(['laytp', 'form'], function() {
            var form = layui.form, layer = layui.layer;
            facade.ajax({url: ask_opt_add_flow_used, data:{explain:explain}}).done(function(res){
                if (res.code === 2000) {
                    show_flow_used(res.data);
                    render_from();
                }
            });
        });
    }

    function pushFlowUsed(obj){
        var value = $(obj).text();
        var explain = $('#explain').val();
        $('#explain').val(value);
    }

    function delFlowUsed(id){
        layui.use(['laytp', 'form'], function() {
            var form = layui.form, layer = layui.layer;

            facade.ajax({url: ask_opt_del_flow_used, data:{id:id}}).done(function(res){
                if (res.code === 2000) {
                    show_flow_used(res.data);
                    render_from();
                }
            });
        });
    }

</script>
</body>
</html>
